<?php

/* set mysql connect variables for reading and writing */
$view_connect = mysql_connect($DB_HOST, $DB_VIEW_USER, $DB_VIEW_USER_PASS);
//$write_connect = mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS);
mysql_select_db($DB_NAME, $view_connect);

// the generic mode variable determines what subpage the main.php page includes, 
// which affects what type of data we're working with, or at least the view. 
$mode = $_REQUEST['mode'];

// the generic do variable is used to help tell us what we're doing within a particular mode 
$do = $_REQUEST['do'];

// {{{is this still used?  If not, let's get rid of it.}}}
if ($_POST['age']){
   $age = $_POST['age'];
} else {
   $age = (isset($_GET['age']))? $_GET['age'] : '';
}
if (!$age) {
   $age = 'all';
}

/* sometimes cat comes in post, sometimes as get */
if ($_POST['cat']){
$cat = $_POST['cat'];
} elseif ($_GET['cat']) {
$cat = $_GET['cat'];
}
if (!$cat) $cat = 0;

if (!$HOME_) $HOME_ = $SERVER['PHP_SELF'];

/* define colors */
// {{{I'm not sure that these are still used}}}
$cat_backgroundcolor = '66cc88';
$cat_bordercolor = '0000ff';

$now = time();

$nowstamp = date("Y-m-d H:i:s", $now);
$three_hours_ago  = date('Y-m-d H:i:s',
   mktime(
      date('H', $now)-3,
      date('i', $now), 
      date('s', $now), 
      date('m', $now), 
      date('d', $now), 
      date('Y', $now)
   ));

if ($RESTART_TYPE === 'fixed') {
   // we use this little loop to find out what the date is of the last weekday for restarting stats, ie, what was the date of the last tuesday?
   $StatStartDay = $nowstamp;
   for ($DayCounter = 1; date('l', $StatStartDay) !== $RESTART_WEEK; $DayCounter++) {
	   $StatStartDay = mktime(
	      date('H', $now),
	      date('i', $now),
	      date('s', $now),
	      date('m', $now),
	      date('d', $now)-$DayCounter,
	      date('Y', $now)
	   );
   }
   // once we've got the restart day, we should add the restart time to it, too.
   $statStartTime = $StatStart = date('Y-m-d', $StatStartDay).' '.$RESTART_TIME;
   $StatStart2 = (date('Y-m-d', mktime(date('H', $StatStartDay), date('i', $StatStartDay), date('s', $StatStartDay), date('m', $StatStartDay), date('d', $StatStartDay) - 7, date('Y', $StatStartDay))));
} else if ($RESTART_TYPE === 'flexible') {
   $statRestartRaw = mktime(
      date('H', $now),
      date('i', $now),
      date('s', $now),
      date('m', $now),
      date('d', $now)-7,
      date('Y', $now)
   );
   $statStartTime = $StatStart = date('Y-m-d H:i:s', $statRestartRaw);
   $statStart2 = date ('Y-m-d', $statRestartRaw);
}

// define program-specific functions

// definitions of important functions used throughout ccramp
//include ('./includes/libccramp.inc');

$include_vars = true;

session_start();
$rights = $_SESSION['rights'];
//if (!$_SESSION['rights']) {
//   if (session_id == '') 
//   session_start();   
//   $rights = $_SESSION['rights'];
//}

?>
